package com.zyz.E_面向对象.E_封装;

/**
 * @author: vick
 * @Date: 2025/3/14
 * @Description:
 * @version: 1.0
 */
public class BankAccount {
    private double balance;

    public BankAccount(double balance) {
        if (balance >= 0) {
            this.balance = balance;
        }else {
            this.balance = 0;
        }
    }

    //获取当余额
    public double getBalance() {
        return balance;
    }

    //存款
    public void deposit(double money) {
        if (balance > 0) {
            this.balance += money; //增加余额
        }else {
            System.out.println("存款金额无效");
        }
    }

    //取款
    public void withdraw(double money)  {
        if (money > 0  && money <= balance) {
            this.balance -= money; //增加余额
        }else {
            System.out.println("余额不足或者无效金额");
        }
    }

    public void sout() {
        System.out.println("当前余额：" + balance);
    }

}
